﻿using System;
using UnityEngine;

// Token: 0x020000A7 RID: 167
public class RigidEmitter : MonoBehaviour
{
	// Token: 0x17000065 RID: 101
	// (get) Token: 0x06000536 RID: 1334 RVA: 0x0001EB94 File Offset: 0x0001CD94
	// (set) Token: 0x06000537 RID: 1335 RVA: 0x0001EB9C File Offset: 0x0001CD9C
	public bool Emitting
	{
		get
		{
			return this.emitting;
		}
		set
		{
			this.emitting = value;
		}
	}

	// Token: 0x06000538 RID: 1336 RVA: 0x0001EBA8 File Offset: 0x0001CDA8
	private void Start()
	{
	}

	// Token: 0x06000539 RID: 1337 RVA: 0x0001EBAC File Offset: 0x0001CDAC
	private void Update()
	{
		if (Input.GetKeyDown(this.key))
		{
			this.StartEmit();
		}
		if (this.Emitting)
		{
			this.UpdateEmit();
		}
	}

	// Token: 0x0600053A RID: 1338 RVA: 0x0001EBD8 File Offset: 0x0001CDD8
	public void StartEmit()
	{
		this.Emitting = true;
		this.timer = 0f;
		this.emitCount = 0;
	}

	// Token: 0x0600053B RID: 1339 RVA: 0x0001EBF4 File Offset: 0x0001CDF4
	private void UpdateEmit()
	{
		float num = this.emitTime / ((float)this.emitNum - 1f);
		if (this.timer == 0f)
		{
			this.Emit();
		}
		else
		{
			int num2 = (int)(this.timer / num) + 1;
			while (this.emitCount < num2)
			{
				this.Emit();
			}
		}
		this.timer += Time.deltaTime;
		if (this.emitCount >= this.emitNum)
		{
			this.Emitting = false;
		}
	}

	// Token: 0x0600053C RID: 1340 RVA: 0x0001EC80 File Offset: 0x0001CE80
	private void Emit()
	{
		int num = UnityEngine.Random.Range(0, this.original.Length);
		GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.original[num]);
		gameObject.SetActive(true);
		gameObject.transform.position = base.transform.position;
		gameObject.transform.rotation = base.transform.rotation;
		gameObject.transform.SetParent(this.setParent);
		Rigidbody[] componentsInChildren = gameObject.GetComponentsInChildren<Rigidbody>();
		foreach (Rigidbody rigidbody in componentsInChildren)
		{
			float y = UnityEngine.Random.Range(this.directionMin, this.directionMax);
			float x = UnityEngine.Random.Range(this.elevationMin, this.elevationMax);
			float d = UnityEngine.Random.Range(this.speedMin, this.speedMax);
			Quaternion rotation = base.transform.rotation * Quaternion.Euler(x, y, 0f);
			Vector3 velocity = rotation * Vector3.forward * d;
			rigidbody.velocity = velocity;
		}
		this.emitCount++;
	}

	// Token: 0x04000433 RID: 1075
	public GameObject[] original;

	// Token: 0x04000434 RID: 1076
	[Range(-180f, 0f)]
	public float directionMin;

	// Token: 0x04000435 RID: 1077
	[Range(0f, 180f)]
	public float directionMax;

	// Token: 0x04000436 RID: 1078
	[Range(-180f, 0f)]
	public float elevationMin;

	// Token: 0x04000437 RID: 1079
	[Range(0f, 180f)]
	public float elevationMax;

	// Token: 0x04000438 RID: 1080
	public float speedMin = 1f;

	// Token: 0x04000439 RID: 1081
	public float speedMax = 1f;

	// Token: 0x0400043A RID: 1082
	public float emitTime = 1f;

	// Token: 0x0400043B RID: 1083
	public int emitNum = 1;

	// Token: 0x0400043C RID: 1084
	public Transform setParent;

	// Token: 0x0400043D RID: 1085
	public KeyCode key = KeyCode.Space;

	// Token: 0x0400043E RID: 1086
	private float timer;

	// Token: 0x0400043F RID: 1087
	private int emitCount;

	// Token: 0x04000440 RID: 1088
	private bool emitting;
}
